package com.zj.guava.eventbus.requestAndResponse;

import com.google.common.eventbus.EventBus;
import com.google.common.eventbus.Subscribe;
import org.junit.Test;

import java.util.Arrays;
import java.util.List;

public class ResponseListener {

    @Test
    public void test() {
        EventBus bus = new EventBus();
        bus.register(new RequestListener(bus, new ResponseListener()));
        bus.post(new EventRequest<>("hello world"));
    }

    @Test
    public void test2() {
        EventBus bus = new EventBus();
        bus.register(new RequestListener(bus, new ResponseListener()));
        List<String> list = Arrays.asList("aa", "bb");
        bus.post(new EventRequest<>(list));
    }

    @Subscribe
    public void getResponse(Response<String> req) {
        String res = req.getResponse();
        System.out.println("get the response!" + res);
    }
}
